<template>
  <div>
    <div class="system-user-search mb15">
				<el-input size="default" placeholder="请输入患者名称或id" v-model="name" style="max-width: 180px"> </el-input>
				<el-button size="default" type="primary" @click="list()"  class="ml10">
					<el-icon>
						<ele-Search />
					</el-icon>
					查询
				</el-button>
				<el-button size="default" type="success" @click="onOpenAddPati"  class="ml10">
					<el-icon>
						<ele-FolderAdd />
					</el-icon>
					新增结果
				</el-button>
			</div>
      <el-table
    :data="pagination.records"
    border 
    style="width: 100%">
    <el-table-column  fixed prop="patients.ptCard"  label="病人编号"   width="150"></el-table-column>
    <el-table-column fixed prop="patients.ptName" label="病人姓名"    width="120"> </el-table-column>
    <el-table-column  fixed prop="trId"  label="结果单号"   width="150"></el-table-column>
    <el-table-column prop="departmentClass.dpcName" label="就诊科室"    width="120"> </el-table-column>
    <el-table-column  prop="trComplaint" label="病人主诉"    width="120"> </el-table-column>
    <el-table-column prop="sysUser.userName" label="所属医师" width="120"> </el-table-column>
    <el-table-column   prop="trTemperature" label="体温"   width="120"> </el-table-column>
    <el-table-column  prop="trPulse"  label="脉搏"   width="300">  </el-table-column>
    <el-table-column prop="trPressure" label="血压" width="120"> </el-table-column>
	  <el-table-column  prop="trFamilyHistory"  label="家属病史"   width="120"></el-table-column>
    <el-table-column prop="trResult" label="诊断结果"    width="120"> </el-table-column>
    <el-table-column   prop="trOpinion" label="医生建议"   width="120"> </el-table-column>
    <el-table-column  prop="trCreateTime"  label="就诊时间"   width="300">  </el-table-column>
    <el-table-column fixed="right"  label="操作" width="100">
      <template slot-scope="scope">
     <el-button @click="del(scope.row)"  type="text" size="small">删除</el-button>
    <el-button type="text" size="small" @click="upPatiUI(scope.row)">编辑</el-button>
      </template>
    </el-table-column>
  </el-table>
  <div class="block">
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :hide-on-single-page="true"
      :current-page="pagination.current"
		  :page-sizes="[3,5,8,10]"
		  :page-size="pagination.size"
		  layout="total,sizes, prev, pager, next, jumper"
		  :total="pagination.total">
    </el-pagination>
  </div>
   
   <el-dialog title="添加诊断书" :visible.sync="addTag" :close-on-click-modal="false">
			  <el-form :model="addTreatForm" size="small" label-width="90px">
				<el-row :gutter="35">

          <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12"  >
						<el-form-item label="选择患者">
								<el-select v-model="addTreatForm.ptId" placeholder="请选择" style="width:100%">
            <el-option
             v-for="item in patientsData"
              :key="item.ptId"
              :label="item.ptName"
              :value="item.ptId">
            </el-option>
           </el-select>
						</el-form-item>
					</el-col>

					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12"  >
						<el-form-item label="病人主诉">
							<el-input v-model="addTreatForm.trComplaint" placeholder="请输入病人主诉" clearable></el-input>
						</el-form-item>
					</el-col>


          <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12"  >
						<el-form-item label="体温">
							<el-input   v-model="addTreatForm.trTemperature" placeholder="请输入体温" clearable></el-input>
						</el-form-item>
					</el-col>

           <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12"  >
						<el-form-item label="脉搏">
							<el-input v-model="addTreatForm.trPulse" placeholder="请输入脉搏" clearable></el-input>
						</el-form-item>
					</el-col>

					
           <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12"  >
						<el-form-item label="血压">
							<el-input v-model="addTreatForm.trPressure" placeholder="请输入血压" clearable></el-input>
						</el-form-item>
					</el-col>

           <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12"  >
						<el-form-item label="家属病史">
							<el-input v-model="addTreatForm.trFamilyHistory" placeholder="请输入家属病史" clearable></el-input>
						</el-form-item>
					</el-col>

            <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12"  >
						<el-form-item label="科室类型">
							<el-select v-model="addTreatForm.dpcId" placeholder="请选择"  style="width:100%"  >
            <el-option
             v-for="item in departmentClassData"
              :key="item.dpcId"
              :label="item.dpcName"
              :value="item.dpcId">
            </el-option>
           </el-select>
						</el-form-item>
					</el-col>

           <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24"  >
						<el-form-item label="诊断结果">
							<el-input v-model="addTreatForm.trResult" type="textarea" placeholder="请输入诊断结果" clearable></el-input>
						</el-form-item>
					</el-col>

           <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24"  >
						<el-form-item label="医生建议">
							<el-input v-model="addTreatForm.trOpinion"  type="textarea" placeholder="请输入医生建议" clearable></el-input>
						</el-form-item>
					</el-col>


				</el-row>
			</el-form>
      <template #footer>
				<span class="dialog-footer">
					<el-button @click="onCancel" size="default">取 消</el-button>
					<el-button type="primary" @click="onSubmit" size="default">新 增</el-button>
				</span>
			</template>
			</el-dialog>

         <el-dialog title="修改诊断书" :visible.sync="upTag" :close-on-click-modal="false">
			  <el-form :model="upTreatForm" size="small" label-width="90px">
				<el-row :gutter="35">

          <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12"  >
						<el-form-item label="选择患者">
								<el-select v-model="upTreatForm.ptId" :disabled="true"  placeholder="请选择" style="width:100%">
            <el-option
             v-for="item in patientsData"
              :key="item.ptId"
              :label="item.ptName"
              :value="item.ptId">
            </el-option>
           </el-select>
						</el-form-item>
					</el-col>

					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12"  >
						<el-form-item label="病人主诉">
							<el-input v-model="upTreatForm.trComplaint" placeholder="请输入病人主诉" clearable></el-input>
						</el-form-item>
					</el-col>


          <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12"  >
						<el-form-item label="体温">
							<el-input   v-model="upTreatForm.trTemperature" placeholder="请输入体温" clearable></el-input>
						</el-form-item>
					</el-col>

           <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12"  >
						<el-form-item label="脉搏">
							<el-input v-model="upTreatForm.trPulse" placeholder="请输入脉搏" clearable></el-input>
						</el-form-item>
					</el-col>

					
           <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12"  >
						<el-form-item label="血压">
							<el-input v-model="upTreatForm.trPressure" placeholder="请输入血压" clearable></el-input>
						</el-form-item>
					</el-col>

           <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12"  >
						<el-form-item label="家属病史">
							<el-input v-model="upTreatForm.trFamilyHistory" placeholder="请输入家属病史" clearable></el-input>
						</el-form-item>
					</el-col>

            <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12"  >
						<el-form-item label="科室类型">
							<el-select v-model="upTreatForm.dpcId" placeholder="请选择"  style="width:100%"  >
            <el-option
             v-for="item in departmentClassData"
              :key="item.dpcId"
              :label="item.dpcName"
              :value="item.dpcId">
            </el-option>
           </el-select>
						</el-form-item>
					</el-col>

           <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24"  >
						<el-form-item label="诊断结果">
							<el-input v-model="upTreatForm.trResult" type="textarea" placeholder="请输入诊断结果" clearable></el-input>
						</el-form-item>
					</el-col>

           <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24"  >
						<el-form-item label="医生建议">
							<el-input v-model="upTreatForm.trOpinion"  type="textarea" placeholder="请输入医生建议" clearable></el-input>
						</el-form-item>
					</el-col>


				</el-row>
			</el-form>
      <template #footer>
				<span class="dialog-footer">
					<el-button @click="uponCancel" size="default">取 消</el-button>
					<el-button type="primary" @click="uponSubmit" size="default">新 增</el-button>
				</span>
			</template>
			</el-dialog>


  </div>
</template>

<script>
import treat from '@/api/treat';

export default {
    name: 'patiList',
    methods:{
      //分页
        handleSizeChange(value) {
          this.pagination.size = value
          this.list(this.pagination.current,this.pagination.size);
       },
        handleCurrentChange(value) {
          this.pagination.current = value
          this.list(this.pagination.current,this.pagination.size);
       },
      list(pageym=1,pagesize=8){
            treat.findTreat(pageym,pagesize,this.name).then(resp=>{
               this.pagination=resp;
            });
        },
        del(pat){
         this.$confirm('此操作将永久删除名字为'+pat.patients.ptName+'结果单号为'+pat.trId+'的结果, 是否继续?', '提示', {
                    type: 'warning'
                    }).then(() => {
                        treat.deletepati(pat.trId).then(resp=>{
                          this.$message({type: 'success',message: resp.message});
                           this.list();
                        })
                      
                     
                    }).catch(() => {
                       this.$message({type: 'info',message: '已取消删除'});          
                    });
       } ,
       //显示添加窗体
       onOpenAddPati() {
          treat.getListDto().then(resp=>{
          this.patientsData=resp.patientsList;
          this.departmentClassData=resp.departmentClassList;
       })
          this.addTag=true;
       },
      //关闭添加
    	onCancel () {
         this.addTag = false;
         this.addTreatForm={};
      },
      	uponCancel () {
         this.upTag = false;
         	this.upTreatForm={};
      },
      //添加提交
    	onSubmit() {
        this.addTreatForm.wid=this.$store.state.userInfos.userInfos.user.userId
        treat.addTreat(this.addTreatForm).then(resp=>{
        this.$message({type: 'success',message: resp.message});
            		this.addTag=false;
            		this.addTreatForm={};
            		this.list();
       })
    },
       //显示修改ui
     upPatiUI(pat){
         treat.upTreatUI(pat.trId).then(resp=>{
            this.upTreatForm=resp;
         treat.getListDto().then(resp=>{
          this.patientsData=resp.patientsList;
          this.departmentClassData=resp.departmentClassList;
       })
       this.upTag=true;
         })
     },
     //修改提交
      uponSubmit(){
        treat.upTreat(this.upTreatForm).then(resp=>{
        this.$message({type: 'success',message: resp.message});
            		this.upTag=false;
            		this.upTreatForm={};
            		this.list();
       })
      }
    },
     
        data() {
      return {
        pagination:{},//分页对象
        name:"",//查询参数
        addTag:false,//是否显示添加弹窗
        upTag:false,//是否显示修改弹窗
        addTreatForm:{},//添加结果的对象
        upTreatForm:{},//修改结果的对象
        departmentClassData: [], // 科室
        patientsData: [], // 患者
      }
        }
    ,  
    mounted() {
        this.list(1,8);
    },
}
</script>

<style>

</style>